package com.bjshiwei.zhengu.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bjshiwei.zhengu.R;
import com.bjshiwei.zhengu.bean.SwingBean;

import java.util.List;

/**
 * 作者：Administrator on 2016/10/11 0011 11:09
 * 邮箱：sanjins@126.com
 */


public class AmplitudeAdapter extends MyBaseAdapter<SwingBean>{
    private List<SwingBean> mData;
    private Context mContext;
    public AmplitudeAdapter(Context context, List<SwingBean> datas) {
        super(context, datas);
        mData =datas;
        mContext =context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView==null) {
            convertView = View.inflate(mContext, R.layout.item_updown,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }


        if(!TextUtils.isEmpty(mData.get(position).getName())) {
            viewHolder.mTextViewName.setText(mData.get(position).getName());
        }

        if(!TextUtils.isEmpty(mData.get(position).getId())) {
            viewHolder.mTextViewId.setText(mData.get(position).getId());
        }

        if(!TextUtils.isEmpty(mData.get(position).getPrice())) {
            viewHolder.mTextViewPrice.setText(mData.get(position).getPrice());
        }

        if(!TextUtils.isEmpty(mData.get(position).getSwing())) {
                viewHolder.mTextViewChangeRate.setTextColor(Color.RED);
                viewHolder.mTextViewChangeRate.setText(mData.get(position).getSwing()+"%");
        }

        return convertView;
    }

    static class ViewHolder{
        private TextView mTextViewName ,mTextViewId,mTextViewPrice,mTextViewChangeRate;
        public ViewHolder(View view){
            mTextViewName = (TextView) view.findViewById(R.id.tv_updown_name);
            mTextViewId = (TextView) view.findViewById(R.id.tv_updown_id);
            mTextViewPrice = (TextView) view.findViewById(R.id.tv_updown_price);
            mTextViewChangeRate = (TextView) view.findViewById(R.id.tv_updown_changerate);
        }
    }
}
